﻿using FTBS.Models.DAO;
using FTBS.Models.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FTBS.Models.BLO
{
    public class RoomBLO
    {
        private RoomDAO _roomDao = new RoomDAO();
        private ChairDAO _chairDao = new ChairDAO();
        /// <summary>
        /// Get all room
        /// </summary>
        /// <returns>List of room</returns>
        /// <author>vuongvt</author>
        public IEnumerable<Room> GetListRoom()
        {
            return _roomDao.GetListRoom();
        }

        /// <summary>
        /// Get list room by theaterId. It is used when choose a theater -> load all room of this theater
        /// </summary>
        /// <param name="theaterId">TheaterId</param>
        /// <returns>SelectList of Room</returns>
        /// <author>vuongvt</author>
        public SelectList GetSelectedListRoomByTheater(int theaterId)
        {
            return _roomDao.GetSelectedListRoomByTheater(theaterId);
        }

        /// <summary>
        /// Get list room by theaterId
        /// </summary>
        /// <param name="theaterId"></param>
        /// <returns>List of room</returns>
        /// <author>vuongvt</author>
        public List<Room> GetListRoomByTheater(int theaterId)
        {
            return _roomDao.GetListRoomByTheater(theaterId);
        }
        /// <summary>
        /// Check room if it's ready exist
        /// </summary>
        /// <param name="room"></param>
        /// <returns>boolean</returns>
        /// <author>nguyenht</author>
        public bool CheckIsExisted(Room room)
        {
            return (_roomDao.CheckIsExisted(room));
        }
        public List<Int32> GetFrame(int theaterId) {
            return _roomDao.GetFrame(theaterId);
        }
        /// <summary>
        /// Create a room of a theater
        /// </summary>
        /// <param name="room"></param>
        /// <returns>boolean</returns>
        /// <author>nguyenht</author>
        public bool CreateRoom(Room room)
        {
            var result = _roomDao.Add(room);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// get room by its id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Room GetRoomById(int id)
        {
           var room = _roomDao.GetRoomById(id);
            return room;
        }
        /// <summary>
        /// delete a room
        /// </summary>
        /// <param name="room"></param>
        /// <returns></returns>
        public bool DeleteRoom(Room room)
        {
                var result = _roomDao.Delete(room);
                if (result == 1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        
        public void SaveChange(Room room) {
            _roomDao.SaveChange(room);
        }
        /// <summary>
        /// Check the RoomId is used in Schedule and doesn't have Booked ticket or not
        /// This function is used for user Click to Edit in List Room
        /// </summary>
        /// <param name="showTimeId"></param>
        /// <returns>True: Is Exist ---- False: Not Exist</returns>
        /// <author>VuongVT</author>
        public bool IsRoomUsedInScheduleAndBooked(int roomId)
        {
            return _roomDao.IsRoomUsedInScheduleAndBooked(roomId);
        }

         /// <summary>
        /// Check the ShowTimeId is used in Schedule or not
        /// This function is used for user Click to Delete in List ShowTIme
        /// </summary>
        /// <param name="showTimeId"></param>
        /// <returns>True: Is Exist ---- False: Not Exist</returns>
        /// <author>VuongVT</author>
        public bool IsRoomUsedForSchedule(int roomId)
        {
            return _roomDao.IsRoomUsedForSchedule(roomId);
        }
    }
}